package com.example.zwh.computershop.my_shopp;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.example.zwh.computershop.Myapp;
import com.example.zwh.computershop.R;
import com.example.zwh.computershop.androidUtil.ActivityCollector;
import com.example.zwh.computershop.login.Login;

public class SetupUserActivity extends AppCompatActivity implements View.OnClickListener{
    private Myapp myapp;
    private TextView username;
    private Button layout;
    private Intent intent;
    private Toast toast;

    private LinearLayout my_main;
    private ImageView return_mine;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_user);
        ActivityCollector.addActivity(this);
        initView();
        initEvent();
        initData();
    }
    void initView() {
        myapp = (Myapp) getApplication();

        username = findViewById(R.id.username);
        layout = findViewById(R.id.layout);
        my_main = findViewById(R.id.my_main);
        return_mine = findViewById(R.id.return_mine);
    }
    void initEvent() {
        layout.setOnClickListener(this);
        my_main.setOnClickListener(this);
        return_mine.setOnClickListener(this);
    }
    void initData() {
        username.setText("会员名：" + myapp.getUser().getUsername());
        System.out.println("C"+myapp.getCart().size() + "P"+myapp.getProducts().size());
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.layout:
                toast.makeText(this, "退出登录成功", Toast.LENGTH_SHORT).show();
                myapp.setLoState(0);
                myapp.clearUser();
                myapp.clearCarta();
                myapp.clearOra();
                ActivityCollector.finishAll();
                intent = new Intent(this, Login.class);
                startActivity(intent);
                break;
            case R.id.my_main:
                intent = new Intent(this, UserInfoActivity.class);
                startActivity(intent);
                break;
            case R.id.return_mine:
                finish();
                break;
        }
    }
}
